<?php
/**
 * 角色管理
*/
apf_require_class("Bll_BLL");
apf_require_class('Bll_Hr_OutInterface');
apf_require_class("Bll_Hr_Property");

class Bll_Flow_Role extends BLL {

    public function delete_role($role_id){
        $result = false;
        if(empty($role_id)){
            return $result;
        }
       return $this->get_default_dao()->remove_by_id(intval($role_id));
    }
    /**
     * 员工离职后清除对应角色关系
     * @param unknown_type $uid
     */
    public function delete_role_by_uid($uid){
        $result = false;
        if(empty($uid)){
            return $result;
        }
        return $this->get_default_dao()->remove(array('user_id'=>$uid));
    }
    /**
     * 添加用户角色
     * @param int $role_type
     * @param int $user_id
     * @param int $city_id
     * @param str $user_info
     * @return boolean
     */
    public function add_role($role_type, $user_id, $city_id, $user_info){
        $result = false;
        if(empty($role_type) || empty($city_id) || empty($user_id) || empty($user_info)){
            return $result;
        }
        $re = $this->get_role_list($city_id, $role_type, $user_id);
        if(is_array($re)){
            if($re){
                return $result;
            }
        }else{
            return $result;
        }
        $data = array(
            'role_type' => intval($role_type),
            'user_id'   => intval($user_id),
            'city_id'   => intval($city_id),
            'user_info' => trim($user_info)
        );
        return $this->get_default_dao()->insert($data);
    }

    /**
     * 获取角色列表
     * @param unknown_type $city_id
     * @param unknown_type $role_type
     * @param unknown_type $user_id
     * @return unknown
     */
    public function get_role_list($city_id = 11, $role_type = '', $user_id = ''){
        $where = array(
            'city_id'   => intval($city_id),
        );
        if(!empty($role_type)){
            $where['role_type'] = intval($role_type);
        }
        if(!empty($user_id)){
            $where['user_id'] = intval($user_id);
        }
        $result = $this->get_default_dao()->find($where, '', 0);

        return $result;
    }

    /**
     * 根据user_id查找用户角色
     * @param int $user_id
     * @return multitype:
     */
    public function get_role_by_user_id($user_id){
        $return = array();
        if(empty($user_id)){
            return $return;
        }
        $where = array(
                'user_id'   => intval($user_id),
        );

        $return = $this->get_default_dao()->find($where, '', 0);
        return $return;
    }


    private function get_default_dao ()
    {
        $dao = $this->get_dao('Dao_Flow_Role');
        return $dao;
    }
}
